#include <memory>
#include "err.hpp"
#include "tcp_server.hpp"
#include "protocol.hpp"

void usage(const std::string& proc)
{
    std::cout << "Uasge:\n\t" << proc << " port\n" << std::endl;
}

tcp::response calculate(const tcp::request& req)
{
    task t(req._x, req._y, req._op);
    t();
    INFO("%s", t.result_str().c_str());

    return tcp::response(t.get_res(), t.get_st());
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(CMD_ERR);
    }

    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<tcp::tcp_server> tsvr(new tcp::tcp_server(calculate, port));
    tsvr->init();
    tsvr->start();

    return 0;
}
